package com.woniu.contorller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniu.pojo.User;
import com.woniu.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserContorller {

    @Autowired
    private IUserService iUserService;

//    分页查询全部

    @RequestMapping("/all/{currentPage}/{pageSize}/{name}")
    public IPage<User> listuser(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @PathVariable String name
    ){

        IPage<User> listpage = iUserService.listpage(currentPage, pageSize, name);


        return listpage;
    }
//  根据id删除
    @RequestMapping("/delete/{id}")
    public String deleteuser(@PathVariable Integer id){

        Integer num = iUserService.deleteuser(id);

        return "success";

    }
//    新增
    @PostMapping("/save")
    public String saveuser(@RequestBody User user){
        Integer num = iUserService.saveuser(user);
        return "success";
    }
//修改
    @PutMapping("/uadate")
    public String updateuser(@RequestBody User user){
        Integer num = iUserService.updateuser(user);
        return "success";
    }

}
